/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hu.kovacsp.scala.discovery

import com.weiglewilczek.slf4s.Logging
import net.lag.configgy.Configgy
import org.h2.jdbcx.JdbcDataSource

object Main extends Logging{
  def main(args: Array[String]): Unit={
    logger debug "SLF4S just rocks!"
    println("Hello World from scala-discovery")
    // load our config file and configure logfiles:
    Configgy.configure("src/main/resources/scala-discovery.conf")
    val config = Configgy.config
    val hostname = config.getString("hostname", "localhost")
    println("hostname=" + hostname)
    val ds: JdbcDataSource = new JdbcDataSource;
    ds.setURL("jdbc:h2:˜/test");
    ds.setUser("sa");
    ds.setPassword("sa");
    val conn = ds.getConnection();
    try{
      
      conn.prepareStatement("drop table if exists testtable;").execute();
      conn.prepareStatement(
        "create table testtable ( id INTEGER, "+
        "name VARCHAR);")
      .execute();
      conn.prepareStatement(
        "insert into testtable(id, name) "+
        "values (1, 'testvalue');")
      .execute();
      val rs = conn.prepareStatement(
        "select * from testtable;").executeQuery();

      // Checking if the data is correct
      rs.next();
      println("Id: " + rs.getInt(1) + " Name: "
              + rs.getString(2));
    }catch{
      case t => t.printStackTrace
    }finally{
      conn.close
    }
  }
}
